#!/usr/bin/php
<?php

#######################################################################################################
#Title: Yahoo! Pipe validator
#Description: This script validates a pipe file. It checks if it is just an HTML page indicating an
#             error or if the pipe is empty (i.e., it does not contain "modules") 
#Author: Carlos Rodriguez
#Creation date: 10.06.2011
#Last update  : 10.06.2011
#######################################################################################################

if($argc < 3 || $argv[1] != '-d'){
	echo "Usage: validate_pipe_file.php -d path_of_directory_containing_files.\n"; 
	exit;
}

$dir_path = $argv[2];

if($handle = opendir($dir_path)){
	while(false !== ($file = readdir($handle))){
		$lines = file($dir_path . "/" . $file);

		foreach($lines as $line){
			if(preg_match("/^\<HTML\>/", $line)){
				echo $file . "\n";
				break;
			}
		}

		$has_modules = false;
		foreach($lines as $line){
			if(preg_match("/\"modules\"/", $line)){
				$has_modules = true;
				break;
			}
		}

		if(!$has_modules){
			echo $file . "\n";
		}

	}


	closedir($handle);
}

?>
